﻿@{
    ViewBag.Title = "SalesIndex";
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>

   @*  <link href="~/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />
    <script src="~/libs/jquery/jquery.js"></script>
    <script src="~/layui-v2.5.6/layui/layui.js"></script> *@
    <script src="~/libs/jquery/jquery.js"></script>
    <link href="//unpkg.com/layui@2.9.16/dist/css/layui.css" rel="stylesheet">
    <script src="//unpkg.com/layui@2.9.16/dist/layui.js"></script>

    <div class="layui-inline ">
        退货单号：
        <div class="layui-inline ">
            <input class="layui-input layui-input-inline" name="SalesOrderCode" id="SalesOrderCode" />
        </div>
        采购单号：
        <div class="layui-inline ">
            <input class="layui-input layui-input-inline" name="ProcurementCode" id="ProcurementCode" />
        </div>
        产品名称：
        <div class="layui-inline ">
            <input class="layui-input layui-input-inline" name="ProductName" id="ProductName" />
        </div>
        <br />
       @*  <button type="button" id="clientList" class="layui-btn layui-btn-primary">查询</button> *@
    </div>
    <div class="layui-btn-container layui-col-xs12">
        <button class="layui-btn" id="btnSearch" lay-submit lay-filter="demo-table-search">搜索</button>

        <button type="button" class="layui-btn layui-btn-normal" onclick="add()">添加</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>

</head>

<body>
    <table class="layui-hide" id="demo" lay-filter="test">
    </table>
    <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-xs" lay-event="edit">查看</a>
            <a class="layui-btn layui-btn-xs" lay-event="delete">删除</a>
        @*     <a class="layui-btn-danger layui-btn layui-btn-xs" lay-event="tui">退货</a> *@
    </script>

    <script>
        layui.config({
            version: '1606182314890' //为了更新 js 缓存，可忽略
        });

        layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider'], function () {
            var layer = layui.layer //弹层
                , table = layui.table //表格

            querylist = function () {
                var SalesOrderCode = $("#SalesOrderCode").val();
                var ProcurementCode = $("#ProcurementCode").val();
                var ProductName = $("#ProductName").val();
                // var en = $("#en").val();
                // var isDel = $("#isDel").val();

                table.render({
                    elem: '#demo'
                    , height: 520
                    , url: '/QiData/GetSales'// + name //数据接口
                    , where: {
                          SalesOrderCode : SalesOrderCode
                        , ProcurementCode : ProcurementCode
                        , ProductName: ProductName

                    }
                    , title: '退货'
                    , page: true //开启分页
                    , limit: 10
                    , limits: [3, 6, 9, 12]
                    , cols: [[ //表头
                        { type: 'checkbox', fixed: 'left' }//锁定第一列
                        , { field: 'SalesOrderCode', title: '退货单号', width: 90 }
                        , { field: 'ProductName', title: '产品名称', width: 90 }
                        , { field: 'ProductCode', title: '产品编号', width: 90 }
                        , { field: 'ProductSpecification', title: '产品规格', width: 90 }
                        , { field: 'Unit', title: '单位', width: 130 }
                        , { field: 'UnitPrice', title: '单价', width: 90 }
                        , { field: 'ReturnQuantity', title: '退货数', width: 90 }
                        , { field: 'SaleSum', title: '总额', width: 130 }
                        , { field: 'ProcurementCode', title: '采购单号', width: 130 }
                        , { field: 'CustomerName', title: '供应商名称', width: 130 }
                        , { field: 'MakeTime', title: '创建时间', width: 130 }
                        , { fixed: 'right', width: 165, align: 'center', title: '操作', toolbar: '#barDemo' }
                    ]],
                    done: function () {
                        //表格绑定数据后的回调函数
                        layer.msg('权限展示完成！', {
                            icon: 1,
                            time: 1000
                        });
                    }
                });
            }

            querylist();

            $("#clientList").on("click", function () {
                querylist();
            })



            table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent === 'delete') {
                    layer.confirm('真的删除行么', function () {
                        //alert(data.Id);
                        console.log(data);
                        $.get("/Sales/DelSales?Id=" + data.Id,
                            res => {
                                console.log(res.Id);
                                if (res) {
                                    console.log(res);
                                    layer.msg('删除客户成功', {
                                        icon: 1,
                                        time: 1000
                                    }, function () {
                                        //window.location = '/Client/ClientShow';
                                        querylist();
                                    });
                                }
                                else {
                                    layer.msg('删除客户失败！', {
                                        icon: 1,
                                        time: 1000
                                    });
                                }
                            }
                        )
                    });
                } else if (layEvent === 'edit') {
                    localStorage.setItem("updatesale", JSON.stringify(data));
                    layer.open({
                        type: 2, // page 层类型
                        area: ['90%', '90%'],
                        title: '修改退货',
                        shade: 0.6, // 遮罩透明度
                        shadeClose: true, // 点击遮罩区域，关闭弹层
                        maxmin: true, // 允许全屏最小化
                        anim: 0, // 0-6 的动画形式，-1 不开启
                        content: '/Sales/SalesUpdate?Id=' + data.Id,//'<div style="padding: 32px;">一个普通的页面层，传入了自定义的 HTML</div>'
                    });
                }
            });




        });



        function edit() {

            layer.open({
                type: 2,
                title: '销售退货详情',
                shadeClose: true,
                shade: 0.8,
                area: ['500px', '400px'],
                content: '/Sales/SalesUpdate?id=' + data.Id,
            });
        }


    </script>


</body>


</html>
